import request from '@/utils/request'

/**
 *
 * @param {用户输入的内容} search_key
 * @param {每页条数} per_page
 */

// 获取搜索到问答列表数据
export function getAnswerSearch(search_key, page, per_page, type = 'question') {
  return request({
    url: '/search',
    method: 'get',
    params: {
      search_key,
      page,
      per_page,
      type
    }
  })
}

// 获取搜索到文章列表数据
export function getArticleSearch(search_key, page, per_page, type = 'article') {
  return request({
    url: '/search',
    method: 'get',
    params: {
      search_key,
      page,
      per_page,
      type
    }
  })
}

// 获取搜索到百科列表数据
export function getEncyclopediasSearch(search_key, page, per_page, wiki_type = 'project') {
  return request({
    url: '/search/wiki',
    method: 'get',
    params: {
      search_key,
      page,
      per_page,
      wiki_type
    }
  })
}

// 获取搜索到动态列表数据
export function getMomentSearch(search_key, page, per_page, type = 'moment') {
  return request({
    url: '/search',
    method: 'get',
    params: {
      search_key,
      page,
      per_page,
      type
    }
  })
}

// 获取搜索到商品的数据
export function getSearchProduct(search_key, page, per_page, orderBy, area, product_type = 'ym') {
  if (area) {
    return request({
      url: '/search/product',
      method: 'get',
      params: {
        search_key,
        page,
        per_page,
        orderBy,
        area,
        product_type
      }
    })
  } else {
    return request({
      url: '/search/product',
      method: 'get',
      params: {
        search_key,
        page,
        per_page,
        orderBy,
        product_type
      }
    })
  }
}

// 获取搜索到的日记数据
export function getSearchDiary(search_key, page, per_page) {
  return request({
    url: '/search/diary-group',
    method: 'get',
    params: {
      search_key,
      page,
      per_page
    }
  })
}

// 获取搜索到的医生信息
export function getSearchDoctor(search_key, page, per_page, orderBy, area) {
  if (area) {
    return request({
      url: '/search/doctor',
      method: 'get',
      params: {
        search_key,
        page,
        per_page,
        orderBy,
        area
      }
    })
  } else {
    return request({
      url: '/search/doctor',
      method: 'get',
      params: {
        search_key,
        page,
        per_page,
        orderBy
      }
    })
  }
}
// 获取搜索到的医院信息
export function getSearchHospital(search_key, page, per_page, orderBy, area) {
  if (area) {
    return request({
      url: '/search/hospital',
      method: 'get',
      params: {
        search_key,
        page,
        per_page,
        orderBy,
        area
      }
    })
  } else {
    return request({
      url: '/search/hospital',
      method: 'get',
      params: {
        search_key,
        page,
        per_page,
        orderBy
      }
    })
  }
}
